﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using Caifu.Stats;

namespace Caifu.SpiderService
{
	public partial class ServiceMain : ServiceBase
	{
		public ServiceMain()
		{
			InitializeComponent();
		}

		protected override void OnStart(string[] args)
		{
			ThreadPool.QueueUserWorkItem(Run);
			ThreadPool.QueueUserWorkItem(delegate(object state) { (new NetDailyStat()).Run(); });
		}

		protected override void OnStop()
		{
		}

		/// <summary>
		/// 服务常驻线程
		/// </summary>
		/// <param name="state"></param>
		void Run(object state)
		{
			while (true)
			{
				try
				{
					Caifu.Spiders.SpiderService.Run();
					Caifu.Spiders.CheckService.Run();
				}
				catch (Exception ex)
				{
					ExceptionManager.Catch(ex);
				}

				Thread.Sleep(180 * 1000);
			}
		}
	}
}
